#!/usr/bin/python
#=00 a simple gui
import sys, os
import pygst
pygst.require("0.10")
import gst
import pygtk
pygtk.require('2.0')
import gtk, gtk.glade

#=01 gst.parse_launch()
PIPELINE = """filesrc location=%s ! mad ! alsasink device=plughw:0"""  #01

#=02 connecting the glade file
class GUI:
    def __init__(self):
        gladeFile = os.path.join(os.path.dirname(__file__,), 'gui.glade') #02
        self.xml = gtk.glade.XML(gladeFile, None) #02
        self.xml.signal_autoconnect(self) #02
        window = self.xml.get_widget("main") #02
        window.connect('delete-event', gtk.main_quit) #02
        window.show_all() #02

        # Create the pipeline
        self.pipeline = gst.parse_launch(PIPELINE % (sys.argv[1])) #01

#=03 GTK signals
    def on_playButton_clicked(self, widget): #03
        # Start the pipeline
        self.pipeline.set_state(gst.STATE_PLAYING) #04

#=04 Start/Pause the pipeline
    def on_pauseButton_clicked(self, widget): #03
        # Pause the pipeline
        self.pipeline.set_state(gst.STATE_PAUSED) #04
            
    def on_quit_activate(self, widget):
        gtk.main_quit()

#=05 Use gtk's mainloop
if __name__ == "__main__":
    gui=GUI()
    gtk.main() #05
